package com.atguigu.eduOrder.service.impl;

import com.atguigu.eduOrder.client.CourseClient;
import com.atguigu.eduOrder.client.UcenterClient;
import com.atguigu.eduOrder.entity.Order;
import com.atguigu.eduOrder.mapper.OrderMapper;
import com.atguigu.eduOrder.service.OrderService;
import com.atguigu.eduOrder.utils.OrderNoUtil;
import com.atguigu.vo.UcenterMemberVo;
import com.atguigu.vo.WebCourseInfoVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author smday
 * @since 2020-08-01
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Resource
    private CourseClient courseClient;

    @Resource
    private UcenterClient ucenterClient;

    @Override
    public String createOrder(String courseId, String memberId) {

        //根据用户id获取用户信息
        UcenterMemberVo memberVo = ucenterClient.getInfoById(memberId);
        //根据课程id获取课程信息
        WebCourseInfoVo courseInfoVo = courseClient.getWebCourseInfoVo(courseId);
        String orderNo = OrderNoUtil.getOrderNo();
        Order order = new Order();
        order.setOrderNo(orderNo);
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfoVo.getTitle());
        order.setCourseCover(courseInfoVo.getCover());
        order.setTeacherName(courseInfoVo.getTeacherName());
        order.setTotalFee(courseInfoVo.getPrice());
        order.setMemberId(memberId);
        order.setMobile(memberVo.getMobile());
        order.setNickname(memberVo.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);
        return orderNo;
    }
}
